﻿
using Xacml.Core;
using System;
using System.Xml;

namespace Xacml.Core.Policy
{
  public class CombinerParameterElement : XacmlElement
  {
    private string _parameterName;
    private AttributeValueElement _attributeValue;

    public string ParameterName
    {
      get
      {
        return this._parameterName;
      }
    }

    public AttributeValueElement AttributeValue
    {
      get
      {
        return this._attributeValue;
      }
    }

    public override bool IsReadOnly
    {
      get
      {
        return true;
      }
    }

    public CombinerParameterElement(string parameterName, AttributeValueElement attributeValue, XacmlVersion schemaVersion)
      : base(XacmlSchema.Policy, schemaVersion)
    {
      this._parameterName = parameterName;
      this._attributeValue = attributeValue;
    }

    public CombinerParameterElement(XmlReader reader, XacmlVersion schemaVersion)
      : this(reader, "CombinerParameter", schemaVersion)
    {
    }

    protected CombinerParameterElement(XmlReader reader, string nodeName, XacmlVersion schemaVersion)
      : base(XacmlSchema.Policy, schemaVersion)
    {
      if (reader.LocalName == nodeName && this.ValidateSchema(reader, schemaVersion))
      {
        if (reader.HasAttributes)
        {
          while (reader.MoveToNextAttribute())
          {
            if (reader.LocalName == "ParameterName")
              this._parameterName = reader.GetAttribute("ParameterName");
            else
              this.AttributeFound(reader);
          }
          reader.MoveToElement();
        }
        while (reader.Read())
        {
          switch (reader.LocalName)
          {
            case "AttributeValue":
              this._attributeValue = new AttributeValueElement(reader, schemaVersion);
              break;
          }
          if (reader.LocalName == "CombinerParameter" && reader.NodeType == XmlNodeType.EndElement)
            break;
        }
      }
      else
        throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, new object[1]
        {
          (object) reader.LocalName
        }]);
    }

    protected virtual void AttributeFound(XmlReader reader)
    {
    }
  }
}
